import org.dom4j.Attribute;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
import org.dom4j.io.XMLWriter;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Iterator;
import java.util.List;

/**
 * @deprecated 用于对上古卷轴strings文件转化后的xml文件进行双语拼接
 */
public class TransSkyrim {
    public static void main(String[] args) throws DocumentException, IOException {
        //1.创建Reader对象
        SAXReader reader = new SAXReader();
        //2.加载xml  分别是Skyrim_English_.xml上古卷轴原文，Skyrim_English7_.xml上古卷轴译文
//        Document document0 = reader.read(new File("E:\\games\\新建文件夹\\Skyrim_English_.xml"));
//        Document document1 = reader.read(new File("E:\\games\\新建文件夹\\Skyrim_English7_.xml"));
        Document document0 = reader.read(new File("E:\\games\\新建文件夹\\Update_English_.xml"));
        Document document1 = reader.read(new File("E:\\games\\新建文件夹\\Update_English7_.xml"));
        //3.获取根节点
        Element rootElement0 = document0.getRootElement();
        Element rootElement1 = document1.getRootElement();
        Iterator doc0Iterator = rootElement0.elementIterator();
        Iterator doc1Iterator = rootElement1.elementIterator();
        while (doc0Iterator.hasNext()){
            Element doc0Elem = (Element) doc0Iterator.next();
            Element doc1Elem = (Element) doc1Iterator.next();
            //可以遍历属性值看看
//            List<Attribute> attributes = doc0.attributes();
//            System.out.println("======获取属性值======");
//            for (Attribute attribute : attributes) {
//                System.out.println(attribute.getValue());
//            }
//            System.out.println("======遍历子节点======");
            Iterator iterator0 = doc0Elem.elementIterator();
            Iterator iterator1 = doc1Elem.elementIterator();
//            迭代四次到达要翻译的文本
            for (int i = 0; i < 4; i++) {
                iterator0.next();
                iterator1.next();
            }

            //获取迭代器
            Element doc0Child = (Element) iterator0.next();
            Element doc1Child = (Element) iterator1.next();
            doc0Child.addText("("+doc1Child.getStringValue()+")");
            //可以看看节点值和节点名
//            System.out.println("节点名："+doc0Child.getName()+"---节点值："+doc1Child.getStringValue());

        }

//        将修改后的document写入文件中
//        XMLWriter writer = new XMLWriter(new FileWriter(new File("E:\\games\\新建文件夹\\contact_.xml")));
        XMLWriter writer = new XMLWriter(new FileWriter(new File("E:\\games\\新建文件夹\\contact0_.xml")));
        writer.write(document0);
        writer.close();

    }
}
